//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Build.VERSION;
import com.baidu.trace.a.j;
import com.baidu.trace.c.d;
import com.baidu.trace.c.e;
import java.util.ArrayList;
import java.util.List;

public final class y {
    private WifiManager a;
    private List<ScanResult> b;
    private List<ScanResult> c;
    private long d;

    protected y(Context var1) {
        this.a = (WifiManager)var1.getSystemService("wifi");
    }

    protected final void a(ArrayList<j> var1) {
        if(this.a != null) {
            this.a.startScan();
            this.b = this.a.getScanResults();
        }

        y var2 = this;
        int var3;
        if(this.b != null && this.b.size() > 0) {
            boolean var6 = true;

            for(var3 = this.b.size() - 1; var3 > 0 && var6; --var3) {
                var6 = false;

                for(int var4 = 0; var4 < var3; ++var4) {
                    int var5 = ((ScanResult)var2.b.get(var4)).level;
                    int var7 = ((ScanResult)var2.b.get(var4 + 1)).level;
                    if(var5 < var7) {
                        ScanResult var10 = (ScanResult)var2.b.get(var4 + 1);
                        var2.b.set(var4 + 1, var2.b.get(var4));
                        var2.b.set(var4, var10);
                        var6 = true;
                    }
                }
            }
        }

        long var11;
        if(e.a(this.b, this.c) && (var11 = e.b() - this.d) >= 0L && var11 <= 60L) {
            if(this.b != null) {
                this.b.clear();
                this.b = null;
            }

            this.b = this.c;
        } else {
            if(this.c != null) {
                this.c.clear();
                this.c = null;
            }

            this.c = this.b;
            this.d = e.b();
        }

        if(this.b != null) {
            int var8;
            if(this.b.size() > 15) {
                var8 = 15;
            } else {
                var8 = this.b.size();
            }

            for(var3 = 0; var3 < var8; ++var3) {
                j var9;
                (var9 = new j()).a = d.b(((ScanResult)this.b.get(var3)).BSSID);
                var9.b = Integer.valueOf(((ScanResult)this.b.get(var3)).level).byteValue();
                var9.c = d.a(((ScanResult)this.b.get(var3)).SSID);
                if(!((ScanResult)this.b.get(var3)).capabilities.contains("WPA") && !((ScanResult)this.b.get(var3)).capabilities.contains("wpa") && !((ScanResult)this.b.get(var3)).capabilities.contains("WEP") && !((ScanResult)this.b.get(var3)).capabilities.contains("wep")) {
                    var9.d = 0;
                } else {
                    var9.d = 1;
                }

                var1.add(var9);
            }

        }
    }

    protected final boolean a() {
        boolean var1;
        return this.a == null?false:(!(var1 = this.a.isWifiEnabled()) && VERSION.SDK_INT >= 18?this.a.isScanAlwaysAvailable():var1);
    }

    protected final void b() {
        if(this.b != null) {
            this.b.clear();
            this.b = null;
        }

        if(this.c != null) {
            this.c.clear();
            this.c = null;
        }

    }
}
